﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class UpdateFlowStepInputs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Flow_NewFlowStep nfs = Flow_NewFlowStep_Service.FindFlowStepById(Convert.ToInt32(Request.QueryString["fid"]));
            Label1.Text = "步骤"+nfs.Sort_id.ToString()+" - 编辑可写字段";
            string[] flowStepInputstrs = nfs.Prc_inputs.Split(',');
            Flow_NewFlow nf = Flow_NewFlow_Service.FindByFlowId(nfs.Base_newFlow.NewFlowl_id);
            string formModel = nf.Flow_Form.Form_model;
            formModel = formModel.Replace(">", " >");
            string[] formItems = formModel.Split('<');
            foreach (string var in formItems)
            {
                if (var.ToLower().IndexOf("title=") != -1)
                {
                    int state = 0;
                    string str = var.Substring(var.ToLower().IndexOf("title=") + 6, var.Substring(var.ToLower().IndexOf("title=") + 6).IndexOf(" "));
                    foreach (string s in flowStepInputstrs)
                    {
                        if (str==s)
                        {
                            lbManageInputs.Items.Add(new ListItem(str,str));
                            state = 1;
                            break;
                        }
                    }
                    if (state==0)
                    {
                        lbInputs.Items.Add(new ListItem(str, str));
                    }
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string[] flowStepManagerInputstrs = Request.Form.GetValues("lbManageInputs");
        string flowStepManagerInputstr = "";
        if (flowStepManagerInputstrs != null)
        {
            foreach (string var in flowStepManagerInputstrs)
            {
                flowStepManagerInputstr += var + ",";
            }
        }
        Flow_NewFlowStep nfs = new Flow_NewFlowStep();
        nfs.NewFlowStep_id = Convert.ToInt32(Request.QueryString["fid"]);
        nfs.Prc_inputs = flowStepManagerInputstr;
        if (Flow_NewFlowStep_Service.UpdateFlowStepInputs(nfs))
        {
            Response.Redirect("FlowStepList.aspx?id=" + Request.QueryString["id"] + "&pageIndex=" + Request.QueryString["pageIndex"]);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改失败！请重试！')", true);
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("FlowStepList.aspx?id=" + Request.QueryString["id"]+"&pageIndex="+Request.QueryString["pageIndex"]);
    }
}
